#ifndef XX_YY_BMOCK_bmock_any
#define XX_YY_BMOCK_bmock_any

#include <algorithm>

namespace bmock
{	
	class bmock_any
	{
	public: // structors

		bmock_any()
			: content(0)
		{
		}

		template<typename ValueType>
		bmock_any(const ValueType & value)
			: content(new holder<ValueType>(value))
		{
		}

		bmock_any(const bmock_any & other)
			: content(other.content ? other.content->clone() : 0)
		{
		}

		~bmock_any()
		{
			delete content;
		}

		template<typename ValueType>
		operator ValueType&() {			
			return *(static_cast<bmock_any::holder<ValueType*> *>(content)->held);
		}

	public: // modifiers

		bmock_any & swap(bmock_any & rhs)
		{
			std::swap(content, rhs.content);
			return *this;
		}

		template<typename ValueType>
		bmock_any & operator=(const ValueType & rhs)
		{
			bmock_any(rhs, false).swap(*this);
			return *this;
		}

		bmock_any & operator=(bmock_any rhs)
		{
			rhs.swap(*this);
			return *this;
		}

	public: // queries

		bool empty() const
		{
			return !content;
		}

	public: // types (public so bmock_any_cast can be non-friend)
		class placeholder
		{
		public: // structors

			virtual ~placeholder()
			{
			}

		public: // queries

			virtual placeholder * clone() const = 0;

		};

		template<typename ValueType>
		class holder : public placeholder
		{
		public: // structors
			
			holder(const ValueType & value)
				: held(value)
			{
			}

		public: // queries

			virtual placeholder * clone() const
			{
				return new holder(held);
			}

		public: // representation

			ValueType held;			

		private: // intentionally left unimplemented
			holder & operator=(const holder &);
		};

	public: 
		placeholder * content;

	};	
}

// Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#endif
